<?php
	$this->assign('title','Sistema de Gerenciamento de Confinamento | Lotes');
	$this->assign('nav','lotes');

	$this->display('_Header.tpl.php');
?>

<script type="text/javascript">
	$LAB.script("scripts/app/lotes.js").wait(function(){
		$(document).ready(function(){
			page.init();
		});
		
		// hack for IE9 which may respond inconsistently with document.ready
		setTimeout(function(){
			if (!page.isInitialized) page.init();
		},1000);
	});
</script>

<div class="container">

<h1>
	<i class="icon-th-list"></i> Lotes
	<span id=loader class="loader progress progress-striped active"><span class="bar"></span></span>
	<span class='input-append pull-right searchContainer'>
		<input id='filter' type="text" placeholder="Search..." />
		<button class='btn add-on'><i class="icon-search"></i></button>
	</span>
</h1>

	<!-- underscore template for the collection -->
	<script type="text/template" id="loteCollectionTemplate">
		<table class="collection table table-bordered table-hover">
		<thead>
			<tr>
				<th id="header_IdLote">Id Lote<% if (page.orderBy == 'IdLote') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
				<th id="header_NuCabeca">Nu Cabeca<% if (page.orderBy == 'NuCabeca') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
				<th id="header_NuPesomedio">Nu Pesomedio<% if (page.orderBy == 'NuPesomedio') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
				<th id="header_NuKgganhodia">Nu Kgganhodia<% if (page.orderBy == 'NuKgganhodia') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
				<th id="header_DtEntrada">Dt Entrada<% if (page.orderBy == 'DtEntrada') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
<!-- UNCOMMENT TO SHOW ADDITIONAL COLUMNS
				<th id="header_DtSaida">Dt Saida<% if (page.orderBy == 'DtSaida') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
				<th id="header_NuDiasmeta">Nu Diasmeta<% if (page.orderBy == 'NuDiasmeta') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
				<th id="header_NuPrecoarroba">Nu Precoarroba<% if (page.orderBy == 'NuPrecoarroba') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
				<th id="header_NuPrecoentrada">Nu Precoentrada<% if (page.orderBy == 'NuPrecoentrada') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
				<th id="header_NuPrecosaida">Nu Precosaida<% if (page.orderBy == 'NuPrecosaida') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
-->
			</tr>
		</thead>
		<tbody>
		<% items.each(function(item) { %>
			<tr id="<%= _.escape(item.get('idLote')) %>">
				<td><%= _.escape(item.get('idLote') || '') %></td>
				<td><%= _.escape(item.get('nuCabeca') || '') %></td>
				<td><%= _.escape(item.get('nuPesomedio') || '') %></td>
				<td><%= _.escape(item.get('nuKgganhodia') || '') %></td>
				<td><%if (item.get('dtEntrada')) { %><%= _date(app.parseDate(item.get('dtEntrada'))).format('MMM D, YYYY') %><% } else { %>NULL<% } %></td>
<!-- UNCOMMENT TO SHOW ADDITIONAL COLUMNS
				<td><%if (item.get('dtSaida')) { %><%= _date(app.parseDate(item.get('dtSaida'))).format('MMM D, YYYY') %><% } else { %>NULL<% } %></td>
				<td><%= _.escape(item.get('nuDiasmeta') || '') %></td>
				<td><%= _.escape(item.get('nuPrecoarroba') || '') %></td>
				<td><%= _.escape(item.get('nuPrecoentrada') || '') %></td>
				<td><%= _.escape(item.get('nuPrecosaida') || '') %></td>
-->
			</tr>
		<% }); %>
		</tbody>
		</table>

		<%=  view.getPaginationHtml(page) %>
	</script>

	<!-- underscore template for the model -->
	<script type="text/template" id="loteModelTemplate">
		<form class="form-horizontal" onsubmit="return false;">
			<fieldset>
				<div id="idLoteInputContainer" class="control-group">
					<label class="control-label" for="idLote">Id Lote</label>
					<div class="controls inline-inputs">
						<span class="input-xlarge uneditable-input" id="idLote"><%= _.escape(item.get('idLote') || '') %></span>
						<span class="help-inline"></span>
					</div>
				</div>
				<div id="nuCabecaInputContainer" class="control-group">
					<label class="control-label" for="nuCabeca">Nu Cabeca</label>
					<div class="controls inline-inputs">
						<input type="text" class="input-xlarge" id="nuCabeca" placeholder="Nu Cabeca" value="<%= _.escape(item.get('nuCabeca') || '') %>">
						<span class="help-inline"></span>
					</div>
				</div>
				<div id="nuPesomedioInputContainer" class="control-group">
					<label class="control-label" for="nuPesomedio">Nu Pesomedio</label>
					<div class="controls inline-inputs">
						<input type="text" class="input-xlarge" id="nuPesomedio" placeholder="Nu Pesomedio" value="<%= _.escape(item.get('nuPesomedio') || '') %>">
						<span class="help-inline"></span>
					</div>
				</div>
				<div id="nuKgganhodiaInputContainer" class="control-group">
					<label class="control-label" for="nuKgganhodia">Nu Kgganhodia</label>
					<div class="controls inline-inputs">
						<input type="text" class="input-xlarge" id="nuKgganhodia" placeholder="Nu Kgganhodia" value="<%= _.escape(item.get('nuKgganhodia') || '') %>">
						<span class="help-inline"></span>
					</div>
				</div>
				<div id="dtEntradaInputContainer" class="control-group">
					<label class="control-label" for="dtEntrada">Dt Entrada</label>
					<div class="controls inline-inputs">
						<div class="input-append date date-picker" data-date-format="yyyy-mm-dd">
							<input id="dtEntrada" type="text" value="<%= _date(app.parseDate(item.get('dtEntrada'))).format('YYYY-MM-DD') %>" />
							<span class="add-on"><i class="icon-calendar"></i></span>
						</div>
						<span class="help-inline"></span>
					</div>
				</div>
				<div id="dtSaidaInputContainer" class="control-group">
					<label class="control-label" for="dtSaida">Dt Saida</label>
					<div class="controls inline-inputs">
						<div class="input-append date date-picker" data-date-format="yyyy-mm-dd">
							<input id="dtSaida" type="text" value="<%= _date(app.parseDate(item.get('dtSaida'))).format('YYYY-MM-DD') %>" />
							<span class="add-on"><i class="icon-calendar"></i></span>
						</div>
						<span class="help-inline"></span>
					</div>
				</div>
				<div id="nuDiasmetaInputContainer" class="control-group">
					<label class="control-label" for="nuDiasmeta">Nu Diasmeta</label>
					<div class="controls inline-inputs">
						<input type="text" class="input-xlarge" id="nuDiasmeta" placeholder="Nu Diasmeta" value="<%= _.escape(item.get('nuDiasmeta') || '') %>">
						<span class="help-inline"></span>
					</div>
				</div>
				<div id="nuPrecoarrobaInputContainer" class="control-group">
					<label class="control-label" for="nuPrecoarroba">Nu Precoarroba</label>
					<div class="controls inline-inputs">
						<input type="text" class="input-xlarge" id="nuPrecoarroba" placeholder="Nu Precoarroba" value="<%= _.escape(item.get('nuPrecoarroba') || '') %>">
						<span class="help-inline"></span>
					</div>
				</div>
				<div id="nuPrecoentradaInputContainer" class="control-group">
					<label class="control-label" for="nuPrecoentrada">Nu Precoentrada</label>
					<div class="controls inline-inputs">
						<input type="text" class="input-xlarge" id="nuPrecoentrada" placeholder="Nu Precoentrada" value="<%= _.escape(item.get('nuPrecoentrada') || '') %>">
						<span class="help-inline"></span>
					</div>
				</div>
				<div id="nuPrecosaidaInputContainer" class="control-group">
					<label class="control-label" for="nuPrecosaida">Nu Precosaida</label>
					<div class="controls inline-inputs">
						<input type="text" class="input-xlarge" id="nuPrecosaida" placeholder="Nu Precosaida" value="<%= _.escape(item.get('nuPrecosaida') || '') %>">
						<span class="help-inline"></span>
					</div>
				</div>
			</fieldset>
		</form>

		<!-- delete button is is a separate form to prevent enter key from triggering a delete -->
		<form id="deleteLoteButtonContainer" class="form-horizontal" onsubmit="return false;">
			<fieldset>
				<div class="control-group">
					<label class="control-label"></label>
					<div class="controls">
						<button id="deleteLoteButton" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i> Delete Lote</button>
						<span id="confirmDeleteLoteContainer" class="hide">
							<button id="cancelDeleteLoteButton" class="btn btn-mini">Cancel</button>
							<button id="confirmDeleteLoteButton" class="btn btn-mini btn-danger">Confirm</button>
						</span>
					</div>
				</div>
			</fieldset>
		</form>
	</script>

	<!-- modal edit dialog -->
	<div class="modal hide fade" id="loteDetailDialog">
		<div class="modal-header">
			<a class="close" data-dismiss="modal">&times;</a>
			<h3>
				<i class="icon-edit"></i> Edit Lote
				<span id="modelLoader" class="loader progress progress-striped active"><span class="bar"></span></span>
			</h3>
		</div>
		<div class="modal-body">
			<div id="modelAlert"></div>
			<div id="loteModelContainer"></div>
		</div>
		<div class="modal-footer">
			<button class="btn" data-dismiss="modal" >Cancel</button>
			<button id="saveLoteButton" class="btn btn-primary">Save Changes</button>
		</div>
	</div>

	<div id="collectionAlert"></div>
	
	<div id="loteCollectionContainer" class="collectionContainer">
	</div>

	<p id="newButtonContainer" class="buttonContainer">
		<button id="newLoteButton" class="btn btn-primary">Add Lote</button>
	</p>

</div> <!-- /container -->

<?php
	$this->display('_Footer.tpl.php');
?>
